package com.ruoyi.system.config;

import lombok.Data;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import io.minio.MinioClient;
import org.springframework.context.annotation.Configuration;

//@PropertySource("classpath:/config/filestorage/filestorage.properties")
@Configuration
@Data
public class FilestorageAutoConfiguration {
    @Value("${storage.minio.endpoint}")
    private String endpoint;

    @Value("${storage.minio.username}")
    private String userName;

    @Value("${storage.minio.password}")
    private String password;
    /**
     * 获取MinioClient
     */
    @Bean
    @ConditionalOnProperty(name = "storage.active", havingValue = "minio")
    public MinioClient minioClient() {
        return MinioClient.builder()
                .endpoint(endpoint)
                .credentials(userName, password)
                .build();
    }
}
